package com.xnyzc.lhy.mis.controller.cmsapi.driver;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xnyzc.lhy.common.entity.Rv;
import com.xnyzc.lhy.common.exception.PangException;
import com.xnyzc.lhy.common.penum.EErrorCode;
import com.xnyzc.lhy.common.util.CheckUtil;
import com.xnyzc.lhy.common.util.TokenUtil;
import com.xnyzc.lhy.mis.service.cms.driver.IDriverWorkStatisticsService;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Description 司机统计
 * @Author zhuyubin
 * @Date 2019-08-27 22:18
 **/
@RestController
@RequestMapping(value = "cmsapi/cmsdriverWorkStatistics")
public class CmsDriverWorkStatisticsController {

    @Autowired
    private IDriverWorkStatisticsService iDriverWorkStatisticsService;

    /**
     * 司机工作统计*
     * @param current 当前页
     * @param name 司机名
     * @return
     */
    @GetMapping(value = "selectDriverWorkStatisticsPage")
    public Rv selectDriverWorkStatisticsPage(
            @ApiParam(name = "current", value = "当前页", required = true) Long current,
            @ApiParam(name = "name", value = "司机名") String name,
            @ApiParam(name = "phone", value = "手机号") String phone
    ){
        Long sysUserId = TokenUtil.getTokenUserId();
        // TODO 暂时不做校验
        List<String> roleDataScope = TokenUtil.getRoleDataScope();
        String tag = TokenUtil.getTag();
        if(CheckUtil.objIsEmpty(tag)){
            throw PangException.create(EErrorCode.missingAuthArgs);
        }
        if (CheckUtil.objIsEmpty(current)){
            throw PangException.create(EErrorCode.missingArg);
        }
        return Rv.wrap(iDriverWorkStatisticsService.selectDriverWorkStatisticsPage(sysUserId, roleDataScope, tag, current, name, phone));
    }
}
